<!-- 发货 -->
<template>
  <el-dialog
    :title="title"
    :visible.sync="open"
    width="600px"
    append-to-body
    :close-on-click-modal="false"
    @close="closeModal"
  >
    <el-form ref="form" :model="form" :show-message="false" label-width="100px">
      <el-form-item label="快递单号" prop="expressNumber" required>
        <el-input
          v-model.trim="form.expressNumber"
          placeholder="请输入快递单号"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item label="快递公司" prop="expressBrand" required>
        <el-input
          v-model.trim="form.expressBrand"
          placeholder="请输入快递公司"
          clearable
        ></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="open = false">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { updateOrderMailing } from '@/api/order/order.js'
export default {
  data() {
    return {
      title: "确认发货",
      open: false,
      form: {
        orderId: "", // 订单ID
        id: "", // 邮寄ID
        expressNumber: "",
        expressBrand: "",
        mailingStatus: 2
      },
    };
  },
  methods: {
    openModal(orderId, id) {
      this.open = true;
      this.form.orderId = orderId;
      this.form.id = id;
    },
    closeModal() {
      this.$refs["form"].resetFields();
      Object.assign(this.$data, this.$options.data()); // 存在自定义校验规则不能重置data
    },
    submitForm() {
      const that = this;
      that.$refs["form"].validate(async (valid) => {
        if (valid) {
          updateOrderMailing(that.form).then(res=>{
            that.$message.success("发货成功");
            that.$emit("refresh");
            that.closeModal();
          })
        }
      })
    }
  },
};
</script>

<style lang="scss" scoped></style>
